#include "Utility.h"
#include <armadillo>

void display(void)
{	

	glClearColor(0,0,0,1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(GLfloat) ImageWidth / (GLfloat)ImageHeight , 0.5f, 1000.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glViewport(0, 0, ImageWidth, ImageHeight);

	obj_rot[14]=eye_position[2];	

	glLoadMatrixf(obj_rot);

	//glutSolidSphere(2,20,20);

	DrawElement();

	ds->Update(0.1);

	//ds->CalForce();

	

	glutSwapBuffers(); 

	glutPostRedisplay();

}

void Keyboard(unsigned char Key, int x, int y)
{
	switch(Key)
	{
	case 'a':

		ds->Perturb();
		
		break;

	case 's':
		testI++;
		printf("%d\n",testI);
		break;
	}

	glutPostRedisplay();
}

void main(int argc, char *argv[])
{
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(ImageWidth, ImageHeight);
	glutCreateWindow("FLIP");
	InitGL();
	InitElement();
	glutDisplayFunc(display);
	glutKeyboardFunc(Keyboard);

	glui=GLUI_Master.create_glui("Control");

	GLUI_Rollout *Rotation=glui->add_rollout("Rotation");
	GLUI_Rotation *ro=glui->add_rotation_to_panel(Rotation,"World Rotation",(float*)obj_rot);
	ro->reset();

	GLUI_Rollout *Translation=glui->add_rollout("Translation");
	GLUI_Translation *tc=glui->add_translation_to_panel(Translation,"Camera Translation",GLUI_TRANSLATION_Z,&(eye_position[2]));
	tc->set_speed(-0.5);
	tc->set_z(eye_position[2]);


	glutMainLoop();

}